<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    let obj = { name: "张三", age: 16 }
    let proxy = new Proxy(obj, {
        get(target, property) {
            if (target.age < 18) {
                return "未成年人"
            }
            return target[property]
        },
        set(target, property, value) {
            if (property == 'name' && target.age < 18) {
                console.log("未成年人不允许改名字");
                return
            }
            target[property] = value
        }
    })
    console.log(proxy.name);
    proxy.name = "李四"
    console.log(proxy.name);
    proxy.age = 20
    console.log(proxy.name);

</script>

</html>